import React, { Component } from 'react'
import { Spin } from 'antd'

const lazy = (importFunc) => {

  return class Wrapper extends Component {
    constructor(props) {
      super(props)
      this.state = {
        LazyCmp: null
      }
      this.load()
    }
    load () {
      importFunc().then(cmp => {
        this.setState({
          LazyCmp: cmp.default
        })
      })
    }
    render() {
      const {LazyCmp} = this.state
      return LazyCmp ? <LazyCmp {...this.props}></LazyCmp> : <Spin><div></div></Spin>
    }
  }
}

export default lazy